require 'rubygems'
require 'watir'

class Kaixin
    def initialize
        @ie_for_kaixin = Watir::IE.start("http://kaixin001.com")
    end
    
    def login_to_kaixin_with (name, password)
        logout
        set_login_field('email', name)
        set_login_field('password', password)
        click_the_button_id_is('btn_dl')
    end

    def set_login_field (field, value)
        element = @ie_for_kaixin.text_field(:name, field)
        element.set(value)
    end
    
    def click_the_button_id_is(name)
        btn = @ie_for_kaixin.button(:id, name)
        btn.click
    end
    
    def is_logined?
        element = @ie_for_kaixin.text_field(:name, 'email')
        element.disabled
    end
    
    def logout
        @ie_for_kaixin.goto 'http://www.kaixin001.com/login/logout.php'
    end
end